home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / ASM-M68K / DELAY.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  1KB  |  45 lines

  1. #ifndef _M68K_DELAY_H
  2. #define _M68K_DELAY_H
  3.  
  4. /*
  5.  * Copyright (C) 1994 Hamish Macdonald
  6.  *
  7.  * Delay routines, using a pre-computed "loops_per_second" value.
  8.  */
  9.  
  10. extern __inline__ void __delay(unsigned long loops)
  11. {
  12.     __asm__ __volatile__ ("1: subql #1,%0; jcc 1b"
  13.         : "=d" (loops) : "0" (loops));
  14. }
  15.  
  16. /*
  17.  * Use only for very small delays ( < 1 msec).  Should probably use a
  18.  * lookup table, really, as the multiplications take much too long with
  19.  * short delays.  This is a "reasonable" implementation, though (and the
  20.  * first constant multiplications gets optimized away if the delay is
  21.  * a constant)  
  22.  */
  23. extern __inline__ void udelay(unsigned long usecs)
  24. {
  25.     unsigned long tmp;
  26.  
  27.     usecs *= 4295;        /* 2**32 / 1000000 */
  28.     __asm__ ("mulul %2,%0:%1"
  29.         : "=d" (usecs), "=d" (tmp)
  30.         : "d" (usecs), "1" (loops_per_sec));
  31.     __delay(usecs);
  32. }
  33.  
  34. extern __inline__ unsigned long muldiv(unsigned long a, unsigned long b, unsigned long c)
  35. {
  36.     unsigned long tmp;
  37.  
  38.     __asm__ ("mulul %2,%0:%1; divul %3,%0:%1"
  39.         : "=d" (tmp), "=d" (a)
  40.         : "d" (b), "d" (c), "1" (a));
  41.     return a;
  42. }
  43.  
  44. #endif /* defined(_M68K_DELAY_H) */
  45.